package com.hue.gulimail.gulimailsearch.app;

import com.hue.common.to.es.SkuEsModel;
import com.hue.common.utils.R;
import com.hue.gulimail.gulimailsearch.service.ElasticProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/search")
@RestController
public class ElasticSaveController {
    @Autowired
    private ElasticProductService elasticService;

    @PostMapping("/save/product")
    public R saveProduct(@RequestBody List<SkuEsModel> skuEsModels) {
        try {
            elasticService.saveProduct(skuEsModels);
        } catch (Exception e) {
            return R.error().put("msg", e.getMessage());
        }
        return R.ok();
    }
}
